﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace FACUI.BasicClass
{
    /// <summary>
    /// 道岔开关量
    /// </summary>
    public class DcKgl
    {
        public string dbName = "";
        public string fbName = "";
        public string name = "";
        public string sbName = "";
        public string zyName = "";
    }
    /*******************************************/
    /// <summary>
    /// 道岔
    /// </summary>
    public class DC : Sharp
    {
        private int i角度d;
        private int i角度f;
        private int i角度q;
        private Point pointd;
        private Point pointf;
        private Point pointq;
        private static Point temp1 = new Point();
        private static Point temp2 = new Point();
        private static Point temp3 = new Point();
        private static Point temp4 = new Point();
        private static Point temp5 = new Point();
        public char 定反位;
        public Pen 断开笔;

        public DC(MapData mapData, Point pt, int d, string subType)
            : base(mapData, pt, d)
        {
            this.定反位 = '无';
            this.断开笔 = new Pen(Color.LightGray, Sharp.默认画笔.Width);
            base.digitList.Add(new Digit("定位", "DC_L", 1));
            base.digitList.Add(new Digit("反位", "DC_U", 1));
            base.digitList.Add(new Digit("前红", "DC_QH", 1));
            base.digitList.Add(new Digit("前白", "DC_QB", 1));
            base.digitList.Add(new Digit("定红", "DC_DH", 1));
            base.digitList.Add(new Digit("定白", "DC_DB", 1));
            base.digitList.Add(new Digit("反红", "DC_FH", 1));
            base.digitList.Add(new Digit("反白", "DC_FB", 1));
            base.changeStep = 1;
            base.text = "";
            base.sharpType = "sbDC";
            base.sizeDefine = new Size(4, 4);
            this.changeSubType(subType);
        }

        public override void addSize(int r)
        {
            int num = r;
            int num2 = r;
            if ((("0".Equals(base.subType) || "1".Equals(base.subType)) || "5".Equals(base.subType)) || "4".Equals(base.subType))
            {
                if (((base.sizeDefineHeight > 2) && (base.sizeDefineWidth > 2)) || (r > 0))
                {
                    base.sizeDefineWidth += 2 * r;
                    base.sizeDefineHeight += 2 * r;
                    base.pointX -= r;
                    base.pointY -= r;
                }
            }
            else if ("2".Equals(base.subType) || "3".Equals(base.subType))
            {
                base.sizeDefineHeight = 2;
                base.sizeDefineWidth = 2;
                return;
            }
            this.resetSize();
        }

        public override void addSize(int d, Point oldPoint, int oldWidth, int oldHeight, int width, int height)
        {
            if ("0".Equals(base.subType) || "1".Equals(base.subType))
            {
                if ((((d == 0) || (d == 7)) || (d == 1)) && ((base.sizeDefineHeight > 2) || (height < 0)))
                {
                    base.pointY = oldPoint.Y + height;
                    base.sizeDefineHeight = oldHeight - (height * 2);
                }
                if ((((d == 2) || (d == 1)) || (d == 3)) && ((base.sizeDefineWidth > 2) || (width > 0)))
                {
                    if ((base.direction == 0) || (1 == base.direction))
                    {
                        base.pointX = oldPoint.X - width;
                    }
                    base.sizeDefineWidth = oldWidth + (width * 2);
                }
                if ((((d == 4) || (d == 3)) || (d == 5)) && ((base.sizeDefineHeight > 2) || (height > 0)))
                {
                    base.sizeDefineHeight = oldHeight + (height * 2);
                }
                if ((((d == 6) || (d == 5)) || (d == 7)) && ((base.sizeDefineWidth > 2) || (width < 0)))
                {
                    if ((base.direction == 0) || (1 == base.direction))
                    {
                        base.pointX = oldPoint.X + (width * 2);
                    }
                    else
                    {
                        base.pointX = oldPoint.X + width;
                    }
                    base.sizeDefineWidth = oldWidth - (width * 2);
                }
            }
            else if ("2".Equals(base.subType) || "3".Equals(base.subType))
            {
                return;
            }
            if (base.sizeDefineWidth <= 0)
            {
                base.sizeDefineWidth = 2;
            }
            if (base.sizeDefineHeight <= 0)
            {
                base.sizeDefineHeight = 2;
            }
            this.resetSize();
        }

        public override bool changeSubType(string newSubType)
        {
            if (!(((("0".Equals(newSubType) || "1".Equals(newSubType)) || ("2".Equals(newSubType) || "3".Equals(newSubType))) || "4".Equals(newSubType)) || "5".Equals(newSubType)))
            {
                return false;
            }
            if ((!"0".Equals(newSubType) && !"1".Equals(newSubType)) && ("2".Equals(newSubType) || "3".Equals(newSubType)))
            {
                int num1 = base.direction % 4;
                base.sizeDefine = new Size(2, 2);
            }
            base.subType = newSubType;
            this.resetSize();
            return true;
        }

        public override void checkLine(int[][][] array4checkLine)
        {
            int num;
            if ("0".Equals(base.subType) || "1".Equals(base.subType))
            {
                if (0 == base.direction)
                {
                    if (base.sizeDefineWidth == base.sizeDefineHeight)
                    {
                        for (num = (int)((base.sizeDefineWidth * 0.5) + 0.1); num < base.sizeDefineWidth; num++)
                        {
                            Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, base.pointY + ((int)((base.sizeDefineWidth * 0.5) + 0.1)), 0);
                            Sharp.tryAddArray4checkLine(array4checkLine, (base.pointX + num) + 1, ((base.pointY + base.sizeDefineHeight) - num) - 1, 3);
                        }
                    }
                }
                else if (1 == base.direction)
                {
                    if (base.sizeDefineWidth == base.sizeDefineHeight)
                    {
                        for (num = (int)((base.sizeDefineWidth * 0.5) + 0.1); num < base.sizeDefineWidth; num++)
                        {
                            Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, base.pointY + ((int)((base.sizeDefineWidth * 0.5) + 0.1)), 0);
                            Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, base.pointY + num, 1);
                        }
                    }
                }
                else if (2 == base.direction)
                {
                    if (base.sizeDefineWidth == base.sizeDefineHeight)
                    {
                        for (num = 0; num < ((int)((base.sizeDefineWidth * 0.5) + 0.1)); num++)
                        {
                            Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, base.pointY + ((int)((base.sizeDefineWidth * 0.5) + 0.1)), 0);
                            Sharp.tryAddArray4checkLine(array4checkLine, (base.pointX + ((int)((base.sizeDefineWidth * 0.5) + 0.1))) - num, (base.pointY + ((int)((base.sizeDefineWidth * 0.5) + 0.1))) + num, 3);
                        }
                    }
                }
                else if ((3 == base.direction) && (base.sizeDefineWidth == base.sizeDefineHeight))
                {
                    for (num = 0; num < ((int)((base.sizeDefineWidth * 0.5) + 0.1)); num++)
                    {
                        Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, base.pointY + ((int)((base.sizeDefineWidth * 0.5) + 0.1)), 0);
                        Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, base.pointY + num, 1);
                    }
                }
            }
            else if ("2".Equals(base.subType) || "3".Equals(base.subType))
            {
                if (0 == base.direction)
                {
                    if (base.sizeDefineWidth == base.sizeDefineHeight)
                    {
                        Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + 1, (base.pointY + base.sizeDefineHeight) - 1, 3);
                        for (num = 1; num < base.sizeDefineWidth; num++)
                        {
                            Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, (base.pointY + base.sizeDefineHeight) - 1, 0);
                            Sharp.tryAddArray4checkLine(array4checkLine, (base.pointX + num) + 1, ((base.pointY + base.sizeDefineHeight) - num) - 1, 3);
                        }
                    }
                }
                else if (1 == base.direction)
                {
                    if (base.sizeDefineWidth == base.sizeDefineHeight)
                    {
                        Sharp.tryAddArray4checkLine(array4checkLine, base.pointX, base.pointY, 1);
                        for (num = 1; num < base.sizeDefineWidth; num++)
                        {
                            Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, base.pointY + 1, 0);
                            Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, base.pointY + num, 1);
                        }
                    }
                }
                else if (2 == base.direction)
                {
                    Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + base.sizeDefineWidth, base.pointY, 3);
                    if (base.sizeDefineWidth == base.sizeDefineHeight)
                    {
                        for (num = 0; num < (base.sizeDefineWidth - 1); num++)
                        {
                            Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, base.pointY + 1, 0);
                            Sharp.tryAddArray4checkLine(array4checkLine, ((base.pointX + base.sizeDefineWidth) - num) - 1, (base.pointY + num) + 1, 3);
                        }
                    }
                }
                else if (3 == base.direction)
                {
                    Sharp.tryAddArray4checkLine(array4checkLine, (base.pointX + base.sizeDefineWidth) - 1, (base.pointY + base.sizeDefineHeight) - 1, 1);
                    if (base.sizeDefineWidth == base.sizeDefineHeight)
                    {
                        for (num = 0; num < (base.sizeDefineWidth - 1); num++)
                        {
                            Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, (base.pointY + base.sizeDefineHeight) - 1, 0);
                            Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, base.pointY + num, 1);
                        }
                    }
                }
            }
            else if (0 == base.direction)
            {
                if (base.sizeDefineWidth == base.sizeDefineHeight)
                {
                    for (num = 0; num < ((int)((base.sizeDefineWidth * 0.5) + 0.1)); num++)
                    {
                        Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + ((int)((base.sizeDefineWidth * 0.5) + 0.1)), base.pointY + num, 2);
                        Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, base.pointY + num, 1);
                    }
                }
            }
            else if (1 == base.direction)
            {
                if (base.sizeDefineWidth == base.sizeDefineHeight)
                {
                    for (num = 0; num < ((int)((base.sizeDefineWidth * 0.5) + 0.1)); num++)
                    {
                        Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + ((int)((base.sizeDefineWidth * 0.5) + 0.1)), (base.pointY + ((int)((base.sizeDefineWidth * 0.5) + 0.1))) + num, 2);
                        Sharp.tryAddArray4checkLine(array4checkLine, (base.pointX + ((int)((base.sizeDefineWidth * 0.5) + 0.1))) - num, (base.pointY + ((int)((base.sizeDefineWidth * 0.5) + 0.1))) + num, 3);
                    }
                }
            }
            else if (2 == base.direction)
            {
                if (base.sizeDefineWidth == base.sizeDefineHeight)
                {
                    for (num = (int)((base.sizeDefineWidth * 0.5) + 0.1); num < base.sizeDefineWidth; num++)
                    {
                        Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + ((int)((base.sizeDefineWidth * 0.5) + 0.1)), base.pointY + num, 2);
                        Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + num, base.pointY + num, 1);
                    }
                }
            }
            else if ((3 == base.direction) && (base.sizeDefineWidth == base.sizeDefineHeight))
            {
                for (num = 0; num < ((int)((base.sizeDefineWidth * 0.5) + 0.1)); num++)
                {
                    Sharp.tryAddArray4checkLine(array4checkLine, base.pointX + ((int)((base.sizeDefineWidth * 0.5) + 0.1)), base.pointY + num, 2);
                    Sharp.tryAddArray4checkLine(array4checkLine, (base.pointX + base.sizeDefineWidth) - num, base.pointY + num, 3);
                }
            }
        }

        public override void createDigit(string kglDesc)
        {
            string[] strArray = kglDesc.Split(new char[] { ',' });
            Digit digit = null;
            string[] strArray2 = strArray[2].Split(new char[] { ';' });
            digit = base.getDigit("DC_L");
            digit.name = strArray2[0];
            digit.isLogic = "1".Equals(strArray2[1]);
            digit.ad = int.Parse(strArray2[2]);
            strArray2 = strArray[3].Split(new char[] { ';' });
            digit = base.getDigit("DC_U");
            digit.name = strArray2[0];
            digit.isLogic = "1".Equals(strArray2[1]);
            digit.ad = int.Parse(strArray2[2]);
            strArray2 = strArray[4].Split(new char[] { ';' });
            digit = base.getDigit("DC_QH");
            digit.name = strArray2[0];
            digit.isLogic = "1".Equals(strArray2[1]);
            digit.ad = int.Parse(strArray2[2]);
            strArray2 = strArray[5].Split(new char[] { ';' });
            digit = base.getDigit("DC_QB");
            digit.name = strArray2[0];
            digit.isLogic = "1".Equals(strArray2[1]);
            digit.ad = int.Parse(strArray2[2]);
            strArray2 = strArray[6].Split(new char[] { ';' });
            digit = base.getDigit("DC_DH");
            digit.name = strArray2[0];
            digit.isLogic = "1".Equals(strArray2[1]);
            digit.ad = int.Parse(strArray2[2]);
            strArray2 = strArray[7].Split(new char[] { ';' });
            digit = base.getDigit("DC_DB");
            digit.name = strArray2[0];
            digit.isLogic = "1".Equals(strArray2[1]);
            digit.ad = int.Parse(strArray2[2]);
            strArray2 = strArray[8].Split(new char[] { ';' });
            digit = base.getDigit("DC_FH");
            digit.name = strArray2[0];
            digit.isLogic = "1".Equals(strArray2[1]);
            digit.ad = int.Parse(strArray2[2]);
            strArray2 = strArray[9].Split(new char[] { ';' });
            digit = base.getDigit("DC_FB");
            digit.name = strArray2[0];
            digit.isLogic = "1".Equals(strArray2[1]);
            digit.ad = int.Parse(strArray2[2]);
        }

        public override double distance(Point p, Size r)
        {
            double num = Math.Pow((p.X - (((((double)(this.rectReal.Right + this.rectReal.Left)) / 2.0) * r.Width) / 2.0)) / 2.0, 2.0);
            double num2 = Math.Pow((p.Y - (((((double)(this.rectReal.Bottom + this.rectReal.Top)) / 2.0) * r.Height) / 2.0)) / 2.0, 2.0);
            int direction = base.direction;
            return Math.Sqrt(num + num2);
        }

        public override void draw(Graphics g, MapSet ct, Pen usePen)
        {
            if (base.inShowArea())
            {
                Point pointd;
                int num;
                this.resetSize();
                Rectangle layoutRectangle = new Rectangle(((this.rectReal.Left * ct.gridsize.Width) / 2) + ct.offset.X, ((this.rectReal.Top * ct.gridsize.Height) / 2) + ct.offset.Y, Sharp.txtAreaSize.Width * ct.gridsize.Width, Sharp.txtAreaSize.Height * ct.gridsize.Width);
                StringFormat format = new StringFormat(StringFormatFlags.NoClip)
                {
                    Alignment = StringAlignment.Center,
                    LineAlignment = StringAlignment.Center
                };
                base.linePen.Color = base.lineColor;
                base.linePen.Width = ct.lineWidth;
                Pen pen = (usePen != null) ? usePen : base.linePen;
                pen.Width = (ct.gridsize.Width >= 8) ? pen.Width : 1f;
                pen.Color = (base.text.Length > 0) ? pen.Color : Color.Yellow;
                if (MapData.开始打印)
                {
                    pen = new Pen(Color.Black, pen.Width);
                }
                Pen pen2 = pen;
                this.断开笔 = new Pen(Color.FromArgb(100, usePen.Color.R, usePen.Color.G, usePen.Color.B), Sharp.默认画笔.Width);
                this.断开笔.DashStyle = DashStyle.Dot;

                if (("0".Equals(base.subType) && (this.定反位 == '定')) || (("1".Equals(base.subType) && (this.定反位 == '反')) || (this.定反位 == '无')))
                {
                    pen = pen2;
                }
                else
                {
                    pen = this.断开笔;
                }
                if ("0".Equals(base.subType) || "1".Equals(base.subType))
                {
                    this.pointq.X = base.pointX + (base.sizeDefineWidth / 2);
                    this.pointq.Y = base.pointY + (base.sizeDefineHeight / 2);
                    temp1 = base.grid2pix(this.pointq, ct.gridsize, ct.offset);
                    if (0 == base.direction)
                    {
                        this.pointd.X = base.pointX + base.sizeDefineWidth;
                        this.pointd.Y = base.pointY + ((int)(base.sizeDefineHeight * 0.5));
                        this.pointf.X = base.pointX + base.sizeDefineWidth;
                        int sizeDefineHeight = base.sizeDefineHeight;
                        this.pointf.Y = base.pointY;
                        temp2 = base.grid2pix(this.pointd, ct.gridsize, ct.offset);
                        temp3 = base.grid2pix(this.pointf, ct.gridsize, ct.offset);
                        this.i角度q = 180;
                        this.i角度d = 0;
                        this.i角度f = 0x2d;
                        if ("1".Equals(base.subType))
                        {
                            pointd = this.pointd;
                            this.pointd = this.pointf;
                            this.pointf = pointd;
                            num = this.i角度d;
                            this.i角度d = this.i角度f;
                            this.i角度f = num;
                        }
                        g.DrawLine(pen, temp1, temp2);
                        temp4 = temp1;
                        temp4.Offset(0, -4);
                        temp5 = temp1;
                        temp5.Offset(4, -4);
                        if (this.定反位 == '无')
                        {
                            g.DrawLines(pen,new Point[]{temp4,temp5, temp3});
                        }
                        else
                        {
                            if (((("1".Equals(base.subType)) && (this.定反位 == '定')) || (("0".Equals(base.subType)) && (this.定反位 == '反'))))
                            {
                                pen = pen2;
                            }
                            else
                            {
                                pen = this.断开笔;
                            }
                            g.DrawLine(pen, temp1, temp3);
                        }
                        layoutRectangle.Y = temp1.Y + 3;
                        layoutRectangle.X -= (layoutRectangle.Width - (temp2.X - temp1.X)) / 2;
                        format.LineAlignment = StringAlignment.Near;
                    }
                    else if (1 == base.direction)
                    {
                        this.pointd.X = base.pointX + base.sizeDefineWidth;
                        this.pointd.Y = base.pointY + ((int)(base.sizeDefineHeight * 0.5));
                        this.pointf.X = base.pointX + base.sizeDefineWidth;
                        this.pointf.Y = base.pointY + base.sizeDefineHeight;
                        temp2 = base.grid2pix(this.pointd, ct.gridsize, ct.offset);
                        temp3 = base.grid2pix(this.pointf, ct.gridsize, ct.offset);
                        this.i角度q = 180;
                        this.i角度d = 0;
                        this.i角度f = 0x13b;
                        if ("1".Equals(base.subType))
                        {
                            pointd = this.pointd;
                            this.pointd = this.pointf;
                            this.pointf = pointd;
                            num = this.i角度d;
                            this.i角度d = this.i角度f;
                            this.i角度f = num;
                        }
                        g.DrawLine(pen, temp1, temp2);
                        temp4 = temp1;
                        temp4.Offset(0, 4);
                        temp5 = temp1;
                        temp5.Offset(4, 4);
                        if (this.定反位 == '无')
                        {
                            g.DrawLines(pen, new Point[] { temp4, temp5, temp3 });
                        }
                        else
                        {
                            if (((("1".Equals(base.subType)) && (this.定反位 == '定')) || (("0".Equals(base.subType)) && (this.定反位 == '反'))))
                            {
                                pen = pen2;
                            }
                            else
                            {
                                pen = this.断开笔;
                            }
                            g.DrawLine(pen, temp1, temp3);
                        }
                        layoutRectangle.Y = (temp1.Y - layoutRectangle.Height) - 3;
                        layoutRectangle.X -= (layoutRectangle.Width - (temp2.X - temp1.X)) / 2;
                        format.LineAlignment = StringAlignment.Far;
                    }
                    else if (2 == base.direction)
                    {
                        int sizeDefineWidth = base.sizeDefineWidth;
                        this.pointd.X = base.pointX;
                        this.pointd.Y = base.pointY + ((int)(base.sizeDefineHeight * 0.5));
                        int num3 = base.sizeDefineWidth;
                        this.pointf.X = base.pointX;
                        this.pointf.Y = base.pointY + base.sizeDefineHeight;
                        temp2 = base.grid2pix(this.pointd, ct.gridsize, ct.offset);
                        temp3 = base.grid2pix(this.pointf, ct.gridsize, ct.offset);
                        this.i角度q = 0;
                        this.i角度d = 180;
                        this.i角度f = 0xe1;
                        if ("1".Equals(base.subType))
                        {
                            pointd = this.pointd;
                            this.pointd = this.pointf;
                            this.pointf = pointd;
                            num = this.i角度d;
                            this.i角度d = this.i角度f;
                            this.i角度f = num;
                        }
                        g.DrawLine(pen, temp1, temp2);
                        temp4 = temp1;
                        temp4.Offset(0, 4);
                        temp5 = temp1;
                        temp5.Offset(-4, 4);
                        if (this.定反位 == '无')
                        {
                            g.DrawLines(pen, new Point[] { temp4, temp5, temp3 });
                        }
                        else
                        {
                            if (((("1".Equals(base.subType)) && (this.定反位 == '定')) || (("0".Equals(base.subType)) && (this.定反位 == '反'))))
                            {
                                pen = pen2;
                            }
                            else
                            {
                                pen = this.断开笔;
                            }
                            g.DrawLine(pen, temp1, temp3);
                        }
                        layoutRectangle.Y = (temp1.Y - layoutRectangle.Height) - 3;
                        layoutRectangle.X -= (layoutRectangle.Width + (temp2.X - temp1.X)) / 2;
                        format.LineAlignment = StringAlignment.Far;
                    }
                    else if (3 == base.direction)
                    {
                        int num4 = base.sizeDefineWidth;
                        this.pointd.X = base.pointX;
                        this.pointd.Y = base.pointY + ((int)(base.sizeDefineHeight * 0.5));
                        int num5 = base.sizeDefineWidth;
                        this.pointf.X = base.pointX;
                        int num6 = base.sizeDefineHeight;
                        this.pointf.Y = base.pointY;
                        temp2 = base.grid2pix(this.pointd, ct.gridsize, ct.offset);
                        temp3 = base.grid2pix(this.pointf, ct.gridsize, ct.offset);
                        this.i角度q = 0;
                        this.i角度d = 180;
                        this.i角度f = 0x87;
                        if ("1".Equals(base.subType))
                        {
                            pointd = this.pointd;
                            this.pointd = this.pointf;
                            this.pointf = pointd;
                            num = this.i角度d;
                            this.i角度d = this.i角度f;
                            this.i角度f = num;
                        }
                        g.DrawLine(pen, temp1, temp2);
                        temp4 = temp1;
                        temp4.Offset(0, -4);
                        temp5 = temp1;
                        temp5.Offset(-4, -4);
                        if (this.定反位 == '无')
                        {
                            g.DrawLines(pen, new Point[] { temp4, temp5, temp3 });
                        }
                        else
                        {
                            if (((("1".Equals(base.subType)) && (this.定反位 == '定')) || (("0".Equals(base.subType)) && (this.定反位 == '反'))))
                            {
                                pen = pen2;
                            }
                            else
                            {
                                pen = this.断开笔;
                            }
                            g.DrawLine(pen, temp1, temp3);
                        }
                        layoutRectangle.Y = temp1.Y + 3;
                        layoutRectangle.X -= (layoutRectangle.Width + (temp2.X - temp1.X)) / 2;
                        format.LineAlignment = StringAlignment.Near;
                    }
                }
                else if ("2".Equals(base.subType) || "3".Equals(base.subType))
                {
                    if (0 == base.direction)
                    {
                        this.pointq.X = base.pointX;
                        this.pointq.Y = base.pointY + base.sizeDefineHeight;
                        this.pointd.X = base.pointX + base.sizeDefineWidth;
                        this.pointd.Y = (base.pointY + base.sizeDefineHeight) - 1;
                        this.pointf.X = base.pointX + base.sizeDefineWidth;
                        this.pointf.Y = base.pointY;
                        temp2 = base.grid2pix(this.pointd, ct.gridsize, ct.offset);
                        temp3 = base.grid2pix(this.pointf, ct.gridsize, ct.offset);
                        temp1 = base.grid2pix(new Point(base.pointX + 1, (base.pointY + base.sizeDefineHeight) - 1), ct.gridsize, ct.offset);
                        g.DrawLine(pen, temp1, base.grid2pix(this.pointd, ct.gridsize, ct.offset));
                        g.DrawLine(pen, temp1, base.grid2pix(this.pointq, ct.gridsize, ct.offset));
                        temp2 = temp1;
                        temp2.Offset(0, -4);
                        temp3 = temp1;
                        temp3.Offset(4, -4);
                        if (this.定反位 == '无')
                        {
                            g.DrawLines(pen, new Point[] { temp4, temp5, temp3 });
                        }
                        else
                        {
                            if (((("1".Equals(base.subType)) && (this.定反位 == '定')) || (("0".Equals(base.subType)) && (this.定反位 == '反'))))
                            {
                                pen = pen2;
                            }
                            else
                            {
                                pen = this.断开笔;
                            }
                            g.DrawLine(pen, temp1, temp3);
                        }
                        this.i角度q = 0xe1;
                        this.i角度d = 0;
                        this.i角度f = 0x2d;
                        if ("3".Equals(base.subType))
                        {
                            pointd = this.pointd;
                            this.pointd = this.pointf;
                            this.pointf = pointd;
                            num = this.i角度d;
                            this.i角度d = this.i角度f;
                            this.i角度f = num;
                        }
                        layoutRectangle.X = temp1.X - layoutRectangle.Width;
                        layoutRectangle.Y = temp1.Y - layoutRectangle.Height;
                        format.LineAlignment = StringAlignment.Far;
                        format.Alignment = StringAlignment.Far;
                    }
                    else if (1 == base.direction)
                    {
                        this.pointq.X = base.pointX;
                        this.pointq.Y = base.pointY;
                        this.pointd.X = base.pointX + base.sizeDefineWidth;
                        this.pointd.Y = base.pointY + 1;
                        this.pointf.X = base.pointX + base.sizeDefineWidth;
                        this.pointf.Y = base.pointY + base.sizeDefineHeight;
                        temp2 = base.grid2pix(this.pointd, ct.gridsize, ct.offset);
                        temp3 = base.grid2pix(this.pointf, ct.gridsize, ct.offset);
                        g.DrawLine(pen, base.grid2pix(new Point(base.pointX + 1, base.pointY + 1), ct.gridsize, ct.offset), base.grid2pix(this.pointd, ct.gridsize, ct.offset));
                        g.DrawLine(pen, base.grid2pix(this.pointq, ct.gridsize, ct.offset), base.grid2pix(new Point(base.pointX + 1, base.pointY + 1), ct.gridsize, ct.offset));
                        temp1 = base.grid2pix(new Point(base.pointX + 1, base.pointY + 1), ct.gridsize, ct.offset);
                        temp2 = temp1;
                        temp2.Offset(0, 4);
                        temp3 = temp1;
                        temp3.Offset(4, 4);
                        if (this.定反位 == '无')
                        {
                            g.DrawLines(pen,new Point[]{temp2, temp3, base.grid2pix(this.pointf, ct.gridsize, ct.offset)});
                        }
                        else
                        {
                            if (((("1".Equals(base.subType)) && (this.定反位 == '定')) || (("0".Equals(base.subType)) && (this.定反位 == '反'))))
                            {
                                pen = pen2;
                            }
                            else
                            {
                                pen = this.断开笔;
                            }
                            g.DrawLine(pen, temp1, temp3);
                        }
                        this.i角度q = 0x87;
                        this.i角度d = 0;
                        this.i角度f = 0x13b;
                        if ("3".Equals(base.subType))
                        {
                            pointd = this.pointd;
                            this.pointd = this.pointf;
                            this.pointf = pointd;
                            num = this.i角度d;
                            this.i角度d = this.i角度f;
                            this.i角度f = num;
                        }
                        layoutRectangle.X = temp1.X - layoutRectangle.Width;
                        layoutRectangle.Y = temp1.Y;
                        format.LineAlignment = StringAlignment.Near;
                        format.Alignment = StringAlignment.Far;
                    }
                    else if (2 == base.direction)
                    {
                        this.pointq.X = base.pointX + base.sizeDefineWidth;
                        this.pointq.Y = base.pointY;
                        this.pointd.X = base.pointX;
                        this.pointd.Y = base.pointY + 1;
                        this.pointf.X = base.pointX;
                        this.pointf.Y = base.pointY + base.sizeDefineHeight;
                        g.DrawLine(pen, base.grid2pix(this.pointd, ct.gridsize, ct.offset), base.grid2pix(new Point((base.pointX + base.sizeDefineWidth) - 1, base.pointY + 1), ct.gridsize, ct.offset));
                        g.DrawLine(pen, base.grid2pix(new Point((base.pointX + base.sizeDefineWidth) - 1, base.pointY + 1), ct.gridsize, ct.offset), base.grid2pix(this.pointq, ct.gridsize, ct.offset));
                        temp1 = base.grid2pix(new Point((base.pointX + base.sizeDefineWidth) - 1, base.pointY + 1), ct.gridsize, ct.offset);
                        temp2 = temp1;
                        temp2.Offset(0, 4);
                        temp3 = temp1;
                        temp3.Offset(-4, 4);
                        if (this.定反位 == '无')
                        {
                            g.DrawLines(pen,new Point[]{ temp2, temp3, base.grid2pix(this.pointf, ct.gridsize, ct.offset)});
                        }
                        else
                        {
                            if (((("1".Equals(base.subType)) && (this.定反位 == '定')) || (("0".Equals(base.subType)) && (this.定反位 == '反'))))
                            {
                                pen = pen2;
                            }
                            else
                            {
                                pen = this.断开笔;
                            }
                            g.DrawLine(pen, temp1, temp3);
                        }
                        this.i角度q = 0x2d;
                        this.i角度d = 180;
                        this.i角度f = 0xe1;
                        if ("3".Equals(base.subType))
                        {
                            pointd = this.pointd;
                            this.pointd = this.pointf;
                            this.pointf = pointd;
                            num = this.i角度d;
                            this.i角度d = this.i角度f;
                            this.i角度f = num;
                        }
                        layoutRectangle.X = temp1.X;
                        layoutRectangle.Y = temp1.Y;
                        format.LineAlignment = StringAlignment.Near;
                        format.Alignment = StringAlignment.Near;
                    }
                    else if (3 == base.direction)
                    {
                        this.pointq.X = base.pointX + base.sizeDefineWidth;
                        this.pointq.Y = base.pointY + base.sizeDefineHeight;
                        this.pointd.X = base.pointX;
                        this.pointd.Y = (base.pointY + base.sizeDefineHeight) - 1;
                        this.pointf.X = base.pointX;
                        this.pointf.Y = base.pointY;
                        g.DrawLine(pen, base.grid2pix(this.pointd, ct.gridsize, ct.offset), base.grid2pix(new Point((base.pointX + base.sizeDefineWidth) - 1, (base.pointY + base.sizeDefineHeight) - 1), ct.gridsize, ct.offset));
                        g.DrawLine(pen, base.grid2pix(new Point((base.pointX + base.sizeDefineWidth) - 1, (base.pointY + base.sizeDefineHeight) - 1), ct.gridsize, ct.offset), base.grid2pix(this.pointq, ct.gridsize, ct.offset));
                        temp1 = base.grid2pix(new Point((base.pointX + base.sizeDefineWidth) - 1, (base.pointY + base.sizeDefineHeight) - 1), ct.gridsize, ct.offset);
                        temp2 = temp1;
                        temp2.Offset(0, -4);
                        temp3 = temp1;
                        temp3.Offset(-4, -4);
                        if (this.定反位 == '无')
                        {
                            g.DrawLines(pen,new Point[]{ temp2, temp3, base.grid2pix(this.pointf, ct.gridsize, ct.offset)});
                        }
                        else
                        {
                            if (((("1".Equals(base.subType)) && (this.定反位 == '定')) || (("0".Equals(base.subType)) && (this.定反位 == '反'))))
                            {
                                pen = pen2;
                            }
                            else
                            {
                                pen = this.断开笔;
                            }
                            g.DrawLine(pen, temp1, temp3);
                        }
                        this.i角度q = 0x13b;
                        this.i角度d = 180;
                        this.i角度f = 0x87;
                        if ("3".Equals(base.subType))
                        {
                            pointd = this.pointd;
                            this.pointd = this.pointf;
                            this.pointf = pointd;
                            num = this.i角度d;
                            this.i角度d = this.i角度f;
                            this.i角度f = num;
                        }
                        layoutRectangle.X = temp1.X;
                        layoutRectangle.Y = temp1.Y - layoutRectangle.Height;
                        format.LineAlignment = StringAlignment.Far;
                        format.Alignment = StringAlignment.Near;
                    }
                }
                else
                {
                    this.pointq.X = base.pointX + (base.sizeDefineWidth / 2);
                    this.pointq.Y = base.pointY + (base.sizeDefineHeight / 2);
                    temp1 = base.grid2pix(this.pointq, ct.gridsize, ct.offset);
                    if (0 == base.direction)
                    {
                        this.pointd.X = base.pointX + ((int)(base.sizeDefineWidth * 0.5));
                        int num7 = base.sizeDefineHeight;
                        this.pointd.Y = base.pointY;
                        int num8 = base.sizeDefineWidth;
                        this.pointf.X = base.pointX;
                        int num9 = base.sizeDefineHeight;
                        this.pointf.Y = base.pointY;
                        temp2 = base.grid2pix(this.pointd, ct.gridsize, ct.offset);
                        temp3 = base.grid2pix(this.pointf, ct.gridsize, ct.offset);
                        this.i角度q = 270;
                        this.i角度d = 90;
                        this.i角度f = 0x87;
                        if ("5".Equals(base.subType))
                        {
                            pointd = this.pointd;
                            this.pointd = this.pointf;
                            this.pointf = pointd;
                            num = this.i角度d;
                            this.i角度d = this.i角度f;
                            this.i角度f = num;
                        }
                        g.DrawLine(pen, temp1, temp2);
                        temp4 = temp1;
                        temp4.Offset(-4, 0);
                        temp5 = temp1;
                        temp5.Offset(-4, -4);
                        if (this.定反位 == '无')
                        {
                            g.DrawLines(pen,new Point[]{ temp4, temp5, temp3});
                        }
                        else
                        {
                            if (((("1".Equals(base.subType)) && (this.定反位 == '定')) || (("0".Equals(base.subType)) && (this.定反位 == '反'))))
                            {
                                pen = pen2;
                            }
                            else
                            {
                                pen = this.断开笔;
                            }
                            g.DrawLine(pen, temp1, temp3);
                        }
                        layoutRectangle.X = temp1.X + 3;
                        layoutRectangle.Y = temp2.Y - ((layoutRectangle.Height - (temp1.Y - temp2.Y)) / 2);
                        format.Alignment = StringAlignment.Near;
                    }
                    else if (1 == base.direction)
                    {
                        this.pointd.X = base.pointX + ((int)(base.sizeDefineWidth * 0.5));
                        this.pointd.Y = base.pointY + base.sizeDefineHeight;
                        int num10 = base.sizeDefineWidth;
                        this.pointf.X = base.pointX;
                        this.pointf.Y = base.pointY + base.sizeDefineHeight;
                        temp2 = base.grid2pix(this.pointd, ct.gridsize, ct.offset);
                        temp3 = base.grid2pix(this.pointf, ct.gridsize, ct.offset);
                        this.i角度q = 90;
                        this.i角度d = 270;
                        this.i角度f = 0xe1;
                        if ("5".Equals(base.subType))
                        {
                            pointd = this.pointd;
                            this.pointd = this.pointf;
                            this.pointf = pointd;
                            num = this.i角度d;
                            this.i角度d = this.i角度f;
                            this.i角度f = num;
                        }
                        g.DrawLine(pen, temp1, temp2);
                        temp4 = temp1;
                        temp4.Offset(-4, 0);
                        temp5 = temp1;
                        temp5.Offset(-4, 4);
                        if (this.定反位 == '无')
                        {
                            g.DrawLine(pen, temp4, temp5);
                            g.DrawLine(pen, temp5, temp3);
                        }
                        else
                        {
                            if (((("1".Equals(base.subType)) && (this.定反位 == '定')) || (("0".Equals(base.subType)) && (this.定反位 == '反'))))
                            {
                                pen = pen2;
                            }
                            else
                            {
                                pen = this.断开笔;
                            }
                            g.DrawLine(pen, temp1, temp3);
                        }
                        layoutRectangle.X = temp1.X + 3;
                        layoutRectangle.Y = temp2.Y - ((layoutRectangle.Height - (temp1.Y - temp2.Y)) / 2);
                        format.Alignment = StringAlignment.Near;
                    }
                    else if (2 == base.direction)
                    {
                        this.pointd.X = base.pointX + ((int)(base.sizeDefineWidth * 0.5));
                        this.pointd.Y = base.pointY + base.sizeDefineHeight;
                        this.pointf.X = base.pointX + base.sizeDefineWidth;
                        this.pointf.Y = base.pointY + base.sizeDefineHeight;
                        temp2 = base.grid2pix(this.pointd, ct.gridsize, ct.offset);
                        temp3 = base.grid2pix(this.pointf, ct.gridsize, ct.offset);
                        this.i角度q = 90;
                        this.i角度d = 270;
                        this.i角度f = 0x13b;
                        if ("5".Equals(base.subType))
                        {
                            pointd = this.pointd;
                            this.pointd = this.pointf;
                            this.pointf = pointd;
                            num = this.i角度d;
                            this.i角度d = this.i角度f;
                            this.i角度f = num;
                        }
                        g.DrawLine(pen, temp1, temp2);
                        temp4 = temp1;
                        temp4.Offset(4, 0);
                        temp5 = temp1;
                        temp5.Offset(4, 4);
                        if (this.定反位 == '无')
                        {
                            g.DrawLines(pen, new Point[] { temp4, temp5, temp3 });
                        }
                        else
                        {
                            if (((("1".Equals(base.subType)) && (this.定反位 == '定')) || (("0".Equals(base.subType)) && (this.定反位 == '反'))))
                            {
                                pen = pen2;
                            }
                            else
                            {
                                pen = this.断开笔;
                            }
                            g.DrawLine(pen, temp1, temp3);
                        }
                        layoutRectangle.X = (temp1.X - layoutRectangle.Width) - 3;
                        layoutRectangle.Y = temp2.Y - ((layoutRectangle.Height - (temp1.Y - temp2.Y)) / 2);
                        format.Alignment = StringAlignment.Far;
                        format.LineAlignment = StringAlignment.Center;
                    }
                    else if (3 == base.direction)
                    {
                        this.pointd.X = base.pointX + ((int)(base.sizeDefineWidth * 0.5));
                        int num11 = base.sizeDefineHeight;
                        this.pointd.Y = base.pointY;
                        this.pointf.X = base.pointX + base.sizeDefineWidth;
                        int num12 = base.sizeDefineHeight;
                        this.pointf.Y = base.pointY;
                        temp2 = base.grid2pix(this.pointd, ct.gridsize, ct.offset);
                        temp3 = base.grid2pix(this.pointf, ct.gridsize, ct.offset);
                        this.i角度q = 270;
                        this.i角度d = 90;
                        this.i角度f = 0x2d;
                        if ("5".Equals(base.subType))
                        {
                            pointd = this.pointd;
                            this.pointd = this.pointf;
                            this.pointf = pointd;
                            num = this.i角度d;
                            this.i角度d = this.i角度f;
                            this.i角度f = num;
                        }
                        g.DrawLine(pen, temp1, temp2);
                        temp4 = temp1;
                        temp4.Offset(4, 0);
                        temp5 = temp1;
                        temp5.Offset(4, -4);
                        if (this.定反位 == '无')
                        {
                            g.DrawLines(pen, new Point[] { temp4, temp5, temp3 });
                        }
                        else
                        {
                            if (((("1".Equals(base.subType)) && (this.定反位 == '定')) || (("0".Equals(base.subType)) && (this.定反位 == '反'))))
                            {
                                pen = pen2;
                            }
                            else
                            {
                                pen = this.断开笔;
                            }
                            g.DrawLine(pen, temp1, temp3);
                        }
                        layoutRectangle.X = (temp1.X - layoutRectangle.Width) - 3;
                        layoutRectangle.Y = temp2.Y - ((layoutRectangle.Height - (temp1.Y - temp2.Y)) / 2);
                        format.Alignment = StringAlignment.Far;
                        format.LineAlignment = StringAlignment.Center;
                    }
                }
                if (!(base.isHideTxt || (((int)(base.txtSize * ((ct.gridsize.Width * 1.0) / 10.0))) < 4)))
                {
                    g.DrawString(base.text, new Font(base.txtFont, (float)((int)(base.txtSize * ((ct.gridsize.Width * 1.0) / 10.0))), FontStyle.Regular), new SolidBrush(MapData.开始打印 ? Color.Black : base.txtColor), layoutRectangle, format);
                }
            }
        }

        public override Point getPoint(char c)
        {
            Point point = new Point(-1, -1);
            switch (c)
            {
                case 'D':
                    return this.pointd;

                case 'E':
                    return point;

                case 'F':
                    return this.pointf;

                case 'Q':
                    return this.pointq;
            }
            return point;
        }

        public override Point getPoint(char c, out int 方向)
        {
            Point point = this.getPoint(c);
            方向 = 0;
            if (c == 'Q')
            {
                方向 = this.i角度q;
                return point;
            }
            if (c == 'D')
            {
                方向 = this.i角度d;
                return point;
            }
            if (c == 'F')
            {
                方向 = this.i角度f;
            }
            return point;
        }

        public override bool hasHotPoint(int d)
        {
            if ("2".Equals(base.subType) || "3".Equals(base.subType))
            {
                return false;
            }
            return true;
        }

        public override bool hasPoint(Point pt)
        {
            return ((pt.Equals(this.pointq) || pt.Equals(this.pointd)) || pt.Equals(this.pointf));
        }

        public override bool hasPoint(Point pt, out char flag)
        {
            flag = 'N';
            if (pt.Equals(this.pointq))
            {
                flag = 'Q';
                return true;
            }
            if (pt.Equals(this.pointd))
            {
                flag = 'D';
                return true;
            }
            if (pt.Equals(this.pointf))
            {
                flag = 'F';
                return true;
            }
            return false;
        }

        public override void onSpaceChar()
        {
            base.direction = (base.direction + base.changeStep) % 4;
            this.resetSize();
        }

        public override void resetSize()
        {
            if ("0".Equals(base.subType) || "1".Equals(base.subType))
            {
                this.rectReal.Width = base.sizeDefineWidth;
                this.rectReal.Height = base.sizeDefineHeight + 1;
                if (0 == base.direction)
                {
                    this.rectReal.Location = new Point((base.pointX * 2) + base.sizeDefineWidth, base.pointY * 2);
                }
                else if (1 == base.direction)
                {
                    this.rectReal.Location = new Point((base.pointX * 2) + base.sizeDefineWidth, ((base.pointY * 2) + base.sizeDefineHeight) - 1);
                }
                else if (2 == base.direction)
                {
                    this.rectReal.Location = new Point(base.pointX * 2, ((base.pointY * 2) + base.sizeDefineHeight) - 1);
                }
                else if (3 == base.direction)
                {
                    this.rectReal.Location = new Point(base.pointX * 2, base.pointY * 2);
                }
            }
            else if ("2".Equals(base.subType) || "3".Equals(base.subType))
            {
                this.rectReal.Width = base.sizeDefineWidth * 2;
                this.rectReal.Height = base.sizeDefineHeight * 2;
                this.rectReal.Location = new Point(base.pointX * 2, base.pointY * 2);
            }
            else
            {
                this.rectReal.Width = base.sizeDefineWidth + 1;
                this.rectReal.Height = base.sizeDefineHeight;
                if (0 == base.direction)
                {
                    this.rectReal.Location = new Point(base.pointX * 2, base.pointY * 2);
                }
                else if (1 == base.direction)
                {
                    this.rectReal.Location = new Point(base.pointX * 2, (base.pointY * 2) + base.sizeDefineHeight);
                }
                else if (2 == base.direction)
                {
                    this.rectReal.Location = new Point(((base.pointX * 2) + base.sizeDefineWidth) - 1, (base.pointY * 2) + base.sizeDefineHeight);
                }
                else if (3 == base.direction)
                {
                    this.rectReal.Location = new Point(((base.pointX * 2) + base.sizeDefineWidth) - 1, base.pointY * 2);
                }
            }
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder("");
            builder.Append(StringUtil.TrimAndPadRight4ASCII(base.text, 1)).Append("道岔");
            switch (int.Parse(base.subType))
            {
                case 0:
                    builder.Append("->小道岔定位为直:");
                    break;

                case 1:
                    builder.Append("->小道岔定位为弯:");
                    break;

                case 2:
                    builder.Append("->大道岔定位为直:");
                    break;

                case 3:
                    builder.Append("->大道岔定位为弯:");
                    break;

                case 4:
                    builder.Append("->垂直小道岔定位为直:");
                    break;

                case 5:
                    builder.Append("->垂直小道岔定位为弯:");
                    break;
            }
            builder.Append(" 坐标(").Append(base.pointX).Append(',').Append(base.pointY).Append(')');
            return builder.ToString();
        }

        public override string toStringKgl()
        {
            Digit[] digitArray = base.digitList.ToArray();
            StringBuilder builder = new StringBuilder("");
            builder.Append(base.text).Append(",").Append(digitArray[0].name).Append(";").Append(digitArray[0].isLogic ? "1" : "0").Append(";").Append(digitArray[0].ad).Append(",").Append(digitArray[1].name).Append(";").Append(digitArray[1].isLogic ? "1" : "0").Append(";").Append(digitArray[1].ad).Append(",").Append(digitArray[2].name).Append(";").Append(digitArray[2].isLogic ? "1" : "0").Append(";").Append(digitArray[2].ad).Append(",").Append(digitArray[3].name).Append(";").Append(digitArray[3].isLogic ? "1" : "0").Append(";").Append(digitArray[3].ad).Append(",").Append(digitArray[4].name).Append(";").Append(digitArray[4].isLogic ? "1" : "0").Append(";").Append(digitArray[4].ad).Append(",").Append(digitArray[5].name).Append(";").Append(digitArray[5].isLogic ? "1" : "0").Append(";").Append(digitArray[5].ad).Append(",").Append(digitArray[6].name).Append(";").Append(digitArray[6].isLogic ? "1" : "0").Append(";").Append(digitArray[6].ad).Append(",").Append(digitArray[7].name).Append(";").Append(digitArray[7].isLogic ? "1" : "0").Append(";").Append(digitArray[7].ad);
            return builder.ToString();
        }

        public override string toStringXiangshu()
        {
            return string.Concat(new object[] { 
                base.text, ",", base.sharpType, ",", base.subType, ",", (base.lineColor.R + (base.lineColor.G << 8)) + (base.lineColor.B << 0x10), ",", base.direction, ",", base.pointX, ",", base.pointY, ",", base.sizeDefineWidth, ",", 
                base.sizeDefineHeight, ",", base.txtSize, ",", base.txtColor.ToArgb() & 0xffffff, ",", base.txtFont, ",", base.isHideTxt ? "1" : "0"
             });
        }

        public override void xuanzhuan180(Point center)
        {
            base.xuanzhuan180(center);
            switch (base.direction)
            {
                case 0:
                case 2:
                    base.direction = 2 - base.direction;
                    break;

                case 1:
                    base.direction = 3;
                    break;

                case 3:
                    base.direction = 1;
                    break;
            }
            base.pointX -= base.sizeDefineWidth;
            base.pointY -= base.sizeDefineHeight;
        }
    }
}

